#!/bin/sh

echo "###############################################################"
echo "### 新统一支付平台(NUPP)清理所有日志的脚本 "
echo "###############################################################"

APPPATH=/home/gpp/logs

clearlog_one_app(){	
  echo ""

  # 执行清理日志命令
  rm -rf $APPPATH/nupp-$1

  if [ $? == 0 ]; then
    echo "nupp-$1 logs clear success..."
  fi
}

clearlog_nacos(){	
  echo "preparing to clear logs nacos..."

  # 执行清理nacos命令
  rm -rf $APPPATH/nacos

  if [ $? == 0 ]; then
    echo "nacos logs clear success..."
  fi
}

clearlog_nginx(){	
  echo "preparing to clear logs nginx ..."

  # 执行清理nginx命令
  rm -rf $APPPATH/nginx

  if [ $? == 0 ]; then
    echo "nginx logs clear success..."
  fi
}

usage() {
  echo "用法: $0 [参数]"
  echo "参数:"
  echo "    all          清理所有的应用程序包的日志"
  echo "    nacos        清理nacos程序包的日志"
  echo "    nginx        清理nginx服务的日志"
  echo "    settings     清理服务nupp-settings    程序包的日志"
  echo "    notice       清理服务nupp-notice      程序包的日志"
  echo "    security     清理服务nupp-security    程序包的日志"
  echo "    gateway      清理服务nupp-gateway     程序包的日志"
  echo "    routing      清理服务nupp-routing     程序包的日志"
  echo "    channel      清理服务nupp-channel     程序包的日志"
  echo "    business     清理服务nupp-business    程序包的日志"
  echo "    checking     清理服务nupp-checking    程序包的日志"
  echo "    workflow     清理服务nupp-workflow    程序包的日志"
  echo "    scheduler    清理服务nupp-scheduler   程序包的日志"
  echo "    position     清理服务nupp-position    程序包的日志"
  echo "    api-gateway  清理服务nupp-api-gateway 程序包的日志"

}

#### MAIN ####
if [ $# == 0 ]; then
  usage
elif [ $# == 1 ]; then
  case $1 in 
    "channel"|"business"|"checking"|"workflow"|"scheduler"|"notice"|"position"|"settings"|"routing"|"gateway"|"security"|"api-gateway")
      clearlog_one_app $1
      ;;
    "nacos")
      clearlog_nacos
      ;;	  
    "nginx")
      clearlog_nginx
      ;;
    "all")
      # 清理所有程序的日志
      clearlog_one_app "channel"
      clearlog_one_app "business"
      clearlog_one_app "checking"
      clearlog_one_app "workflow"
      clearlog_one_app "scheduler"
      clearlog_one_app "analysis"
      clearlog_one_app "notice"
      clearlog_one_app "position"
      clearlog_one_app "settings"
      clearlog_one_app "routing"
      clearlog_one_app "gateway"
      clearlog_one_app "security"
      clearlog_one_app "api-gateway"
      clearlog_nacos
      clearlog_nginx
      ;;
    *)
      echo "invalid parameter [$1]..."
      ;;	  
  esac
fi



